home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GradientImportUIWin.c
-
- Copyright 1993-1996, Adobe Systems Incorporated.
- All rights reserved.
-
- C source file for MS-Windows specific code
- */
-
- #include "GradientImport.h"
-
- #define STATE_IDLE 0
- #define STATE_AGAIN 1
- #define STATE_CANCEL -1
-
- //#define SDK_VALIDATE WM_USER+100
-
- short state=STATE_IDLE;
- short lastTitem=dRowsItem;
- Boolean Validate (GPtr globals, const HWND hDlg, int *item);
- void ShowOutputBuffer(GPtr globals, HWND hDlg);
-
- /*****************************************************************************/
-
- /* Calculates the rectangle we will want to use for the proxy for an image. */
-
- void GetProxyItemRect (HWND hDlg, Rect *proxyItemRect)
- {
-
- RECT wRect;
-
- GetWindowRect(GetDlgItem(hDlg, kProxyItem), &wRect);
- ScreenToClient (hDlg, (LPPOINT)&wRect);
- ScreenToClient (hDlg, (LPPOINT)&(wRect.right));
-
- proxyItemRect->left = (short)wRect.left;
- proxyItemRect->top = (short)wRect.top;
- proxyItemRect->right = (short)wRect.right;
- proxyItemRect->bottom = (short)wRect.bottom;
-
- }
-
- /*****************************************************************************/
-
- void DoAbout (GPtr globals)
- {
- ShowAbout((AboutRecordPtr)gStuff, hDllInstance, AboutID);
- }
-
- /*****************************************************************************/
-
- void ShowOutputBuffer(GPtr globals, HWND hDlg)
- {
- PSPixelMap pixels;
- PSPixelMask mask;
- PAINTSTRUCT ps;
- Rect itemBounds;
- RECT wRect;
- POINT mapOrigin;
- HDC hDC;
-
- GetWindowRect(GetDlgItem(hDlg, kProxyItem), &wRect);
- mapOrigin.x = 0;
- mapOrigin.y = 0;
- ClientToScreen(hDlg, &mapOrigin);
-
- /* need to create my own outRect
- itemBounds.left = (short)(((wRect.right + wRect.left - gStuff->outRect.right + gStuff->outRect.left) / 2) - mapOrigin.x);
- itemBounds.top = (short)(((wRect.bottom + wRect.top - gStuff->outRect.bottom + gStuff->outRect.top) / 2) - mapOrigin.y);
- itemBounds.right = (short)(itemBounds.left + (gStuff->outRect.right - gStuff->outRect.left));
- itemBounds.bottom = (short)(itemBounds.top + (gStuff->outRect.bottom - gStuff->outRect.top));
- */ // update this when I can
-
- hDC = BeginPaint(hDlg, &ps);
-
- wRect.left = itemBounds.left;
- wRect.top = itemBounds.top;
- wRect.right = itemBounds.right;
- wRect.bottom = itemBounds.bottom;
-
- InflateRect(&wRect, kGutter, kGutter);
- //FillRect(hDC, &wRect, (HBRUSH) (COLOR_WINDOW));
- FrameRect(hDC, &wRect, GetStockObject(BLACK_BRUSH));
- InflateRect(&wRect, -kGutter, -kGutter);
-
- pixels.version = 1;
- /* point these outRect's to your own
- pixels.bounds.top = gStuff->outRect.top;
- pixels.bounds.left = gStuff->outRect.left;
- pixels.bounds.bottom = gStuff->outRect.bottom;
- pixels.bounds.right = gStuff->outRect.right;
- pixels.imageMode = gStuff->imageMode;
- pixels.rowBytes = gStuff->outRowBytes;
- pixels.colBytes = gStuff->outHiPlane - gStuff->outLoPlane + 1;
- pixels.planeBytes = 1;
- pixels.baseAddr = gStuff->outData;
- */ // need to be updated
-
- pixels.mat = NULL;
- pixels.masks = NULL;
- pixels.maskPhaseRow = 0;
- pixels.maskPhaseCol = 0;
-
- /* do something with this mask, layer, and floating stuff */
- #if 0
- if (gStuff->isFloating) {
- mask.next = NULL;
- mask.maskData = gStuff->maskData;
- mask.rowBytes = gStuff->maskRowBytes;
- mask.colBytes = 1;
- mask.maskDescription = kSimplePSMask;
-
- pixels.masks = &mask;
- } else if ((gStuff->inLayerPlanes != 0) && (gStuff->inTransparencyMask != 0)) {
- mask.maskData = ((char *) gStuff->outData) + (gStuff->outHiPlane - gStuff->outLoPlane);
- mask.rowBytes = gStuff->outRowBytes;
- mask.colBytes = gStuff->outHiPlane - gStuff->outLoPlane + 1;
- mask.next = NULL;
- mask.maskDescription = kSimplePSMask;
-
- pixels.masks = &mask;
- }
- // fix the above
- #endif
- mask.next = NULL; // placeholder
-
- (gStuff->displayPixels)(&pixels, &pixels.bounds, itemBounds.top, itemBounds.left, (void *)hDC);
-
- EndPaint(hDlg, (LPPAINTSTRUCT) &ps);
- }
-
- /*****************************************************************************/
- // Because we want to wait until the user changes the focus
- // from an EditText field to something else, and because we
- // want to ignore validation if the user Cancels, this routine
- // does round of validating fields if it's been flagged.
-
- Boolean Validate (GPtr globals, const HWND hDlg, int *item)
- {
- int32 x = 0;
- Boolean retn = true;
- short numberErr = noErr;
-
- switch (*item)
- {
- case dColsItem:
- numberErr = FetchNumber(hDlg,
- dColsItem,
- kColumnsMin,
- kColumnsMax,
- &x);
- if (numberErr != noErr)
- { // shows alert if there's an error
- AlertNumber(hDlg,
- dColsItem,
- kColumnsMin,
- kColumnsMax,
- &x,
- hDllInstance,
- AlertID,
- numberErr);
- retn = false; // had to pop an error, stay here
- }
- break;
- case dRowsItem:
- numberErr = FetchNumber(hDlg,
- dRowsItem,
- kRowsMin,
- kRowsMax,
- &x);
- if (numberErr != noErr)
- { // shows alert if there's an error
- AlertNumber(hDlg,
- dRowsItem,
- kRowsMin,
- kRowsMax,
- &x,
- hDllInstance,
- AlertID,
- numberErr);
- retn = false; // had to pop an error, stay here
- }
- break;
- }
- *item = 0;
- return retn;
- }
-
- /*****************************************************************************/
-
- /* Dialog box code to ask for the acquire parameters. */
-
- BOOL WINAPI UIProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
- {
- static GPtr globals=NULL; /* need to be static */
-
- int32 x = 0;
- static int lastItem = 0;
- int item;
- int cmd;
- short numberErr = noErr;
- static HWND h = NULL; // last window with focus
- static PlatformData *platform;
-
- switch (wMsg)
- {
- case WM_INITDIALOG:
- /* set up globals */
- globals = (GPtr) lParam;
- platform = ((AcquireRecordPtr) gStuff)->platformData;
-
- CenterDialog(hDlg);
-
- // Initialize Images, width and height edit boxes with default values
- StuffNumber(hDlg, dRowsItem, gLastRows);
- StuffNumber(hDlg, dColsItem, gLastCols);
- SetCheckBoxState (hDlg, dInvertItem, (gLastInvert && gStuff->canReadBack));
-
- /* We will only be inverting if we can read the image back. */
-
- if (gStuff->canReadBack)
- EnableControl (hDlg, dInvertItem);
- else
- DisableControl (hDlg, dInvertItem);
-
- // Initialize mode to its default
- SetRadioGroupState(hDlg,
- dFirstModeItem,
- dLastModeItem,
- gLastMode - plugInModeBitmap + dFirstModeItem);
-
- // Rows edit box will get the focus
- SelectTextItem(hDlg, dRowsItem);
- return FALSE;
- break;
- case WM_PAINT:
- return FALSE; // handled it
- break;
- case WM_ACTIVATE:
- if (LOWORD(wParam) == WA_INACTIVE &&
- state == STATE_IDLE &&
- lParam == (LPARAM)platform->hwnd)
- {
- /* Bug in non-modal lets parent get clicked.
- This will post the reversing deactivate and activate
- messages to fix it. */
- h = GetFocus();
- PostMessage((HWND)lParam, WM_ACTIVATE, (WPARAM)WA_INACTIVE,
- (LPARAM)hDlg); // inactivate host
- PostMessage((HWND)hDlg, WM_ACTIVATE, (WPARAM)WA_ACTIVE,
- lParam); // activate us again
- MessageBeep(MB_OK);
- }
- else if (h != NULL) // reset the focus on activate
- {
- SetDialogDefaultItem(hDlg, ok); // outline
- SetFocus(h);
- h = NULL;
- }
- return FALSE; // 0=we handled it
- break;
- case WM_COMMAND:
- item = COMMANDID (wParam); // WIN32 Change
- cmd = HIWORD(wParam);
-
- switch (item)
- {
- case ok:
- if (cmd == BN_CLICKED)
- {
- lastItem = dRowsItem; // force validation
- if (Validate(globals, hDlg, &lastItem))
- {
- numberErr = FetchNumber(hDlg,
- dRowsItem,
- kRowsMin,
- kRowsMax,
- &x);
-
- lastItem = dColsItem;
- if (Validate(globals, hDlg, &lastItem))
- {
- gLastRows = (short)x;
-
- numberErr = FetchNumber(hDlg,
- dColsItem,
- kColumnsMin,
- kColumnsMax,
- &x);
- gLastCols = (short)x;
-
- gLastMode = GetRadioGroupState(hDlg,
- dFirstModeItem,
- dLastModeItem)
- - dFirstModeItem
- + plugInModeBitmap;
- gLastInvert = GetCheckBoxState(hDlg, dInvertItem);
- state = STATE_AGAIN;
- } // bad cols
- } // bad rows
- } // btn clicked
- else Validate(globals, hDlg, &lastItem);
- // btn not clicked but focus may have changed to it so validate
- break;
-
- case cancel:
- if (cmd == BN_CLICKED)
- state = STATE_CANCEL;
- // don't validate ever when we're dealing with cancel
- break;
-
- case dFirstModeItem:
- case dFirstModeItem+1:
- case dFirstModeItem+2:
- case dFirstModeItem+3:
- if (Validate(globals, hDlg, &lastItem))
- if (cmd == BN_CLICKED)
- SetRadioGroupState(hDlg, dFirstModeItem, dLastModeItem, wParam);
- break;
- case dInvertItem:
- if (Validate(globals, hDlg, &lastItem))
- if (cmd == BN_CLICKED)
- ToggleCheckBoxState(hDlg, dInvertItem);
- break;
- case dRowsItem:
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == EN_KILLFOCUS)
- lastTitem = lastItem = dRowsItem; // for validation
- else if (cmd == EN_CHANGE)
- {
- numberErr = FetchNumber(hDlg,
- dRowsItem,
- kRowsMin,
- kRowsMax,
- &x);
- if (numberErr == noErr && x != gLastRows)
- { // different number, update
- /* later implementation
- gLastRows = (short)x;
-
- // Do Filtering operation
- DoFilterRect (globals);
-
- // Invalidate Proxy Item
- GetWindowRect(GetDlgItem(hDlg, kProxyItem), &imageRect);
- ScreenToClient (hDlg, (LPPOINT)&imageRect);
- ScreenToClient (hDlg, (LPPOINT)&(imageRect.right));
- InvalidateRect (hDlg, &imageRect, FALSE);
- */ // for later
- }
- }
- }
- break;
- case dColsItem:
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == EN_KILLFOCUS)
- lastTitem = lastItem = dColsItem; // for validate routine
- else if (cmd == EN_CHANGE)
- {
- numberErr = FetchNumber(hDlg,
- dColsItem,
- kColumnsMin,
- kColumnsMax,
- &x);
- if (numberErr == noErr && x != gLastCols)
- { // different number, update
- /* later implementation
- gLastCols = (short)x;
-
- // Do Filtering operation
- DoFilterRect (globals);
-
- // Invalidate Proxy Item
- GetWindowRect(GetDlgItem(hDlg, kProxyItem), &imageRect);
- ScreenToClient (hDlg, (LPPOINT)&imageRect);
- ScreenToClient (hDlg, (LPPOINT)&(imageRect.right));
- InvalidateRect (hDlg, &imageRect, FALSE);
- */ // for later
- }
- }
- }
- break;
- } /* switch (item) */
- return FALSE;
- break;
-
- default:
- return FALSE; // we didn't handle it FALSE;
- break;
- } /* switch */
- return TRUE; // we didn't handle it FALSE;
- }
-
- /*****************************************************************************/
-
- /* Setup the parameters dialog. Returns TRUE if it succeeds. */
-
- Boolean OpenOurDialog (GPtr globals)
- {
-
- PlatformData *platform;
-
- state = STATE_IDLE;
-
- if (gDialog != NULL)
- {
- SetActiveWindow (gDialog);
- // Select first text item again
- if (lastTitem > 0)
- { // reselect last text item
- SelectTextItem(gDialog, lastTitem);
- lastTitem = 0;
- }
- // set the dialog window the active window
- return TRUE;
- }
- else
- { // dialog not created yet. Do it.
- platform = ((AcquireRecordPtr) gStuff)->platformData;
-
-
- gDialog = CreateDialogParam(hDllInstance,
- (LPSTR)"UIPARAM",
- (HWND)platform->hwnd,
- (DLGPROC)UIProc, // FARPROC
- (LPARAM)globals);
-
- if (gDialog)
- { // got it. Show it.
- ShowWindow(gDialog, SW_NORMAL);
- UpdateWindow(gDialog);
- return TRUE;
- }
- else // lost it.
- return FALSE; // Couldnt put up the dialog box
- }
- }
-
- /*****************************************************************************/
-
- /* Run the parameters dialog. Returns TRUE if it succeeds. */
-
- Boolean RunOurDialog (GPtr globals)
- {
- // We are basically waiting for user to press "Import" or "Cancel" from the
- // dialog
-
- //HWND pWin = NULL; // parent window
- MSG msg;
-
- // First post a message to the host to update itself
-
- /*
- pWin = GetParent(gDialog); // gets the parent (host)
- RedrawWindow(pWin, NULL, NULL, RDW_INTERNALPAINT | RDW_UPDATENOW | RDW_ALLCHILDREN);
- */
-
- while (GetMessage((LPMSG)&msg, NULL, 0, 0))
- {
- if (!IsDialogMessage((HWND)gDialog, &msg))
- { // wasn't for our dialog. Send it on its way.
- TranslateMessage((LPMSG)&msg);
- DispatchMessage ((LPMSG)&msg);
- }
-
-
- // state is set in UIProc based on the user response
- // The only way this function would return is by the user responding with
- // either pressing the "Import" or the "Cancel" button
- if (state == STATE_AGAIN)
- {
- return TRUE;
- }
- else if (state == STATE_CANCEL)
- {
- return FALSE;
- }
- }
- }
-
-
- /*****************************************************************************/
-
- /* Close the parameters dialog. */
-
- void CloseOurDialog (GPtr globals)
- {
-
- if (gDialog != NULL)
- {
- DestroyWindow(gDialog);
- gDialog = NULL;
- }
-
- }
-
- /****************************************************************************/
- /* Example for ShowAlert() function which takes a string ID as parameter */
- /* and displays a message box */
- /****************************************************************************/
-
- short ShowAlert (short stringID)
- {
- char szMessage[256];
- char szTitle[128];
-
- LoadString(hDllInstance, stringID, szMessage, sizeof szMessage);
- LoadString(hDllInstance, 2, szTitle, sizeof szTitle);
- return ( MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONHAND) );
-
- }
-
- /* Initialization and termination code for window's dlls. */
-
- // Win32 Change
- #ifdef WIN32
-
- // Every 32-Bit DLL has an entry point DLLInit
-
- BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
- {
-
- if (fdwReason == DLL_PROCESS_ATTACH)
- hDllInstance = hInstance;
-
- return TRUE; // Indicate that the DLL was initialized successfully.
- }
-
- #else
- /* ------------------------------------------------
- * Code from Borland's window's dll example code.
- * ------------------------------------------------
- */
- #if defined(__BORLANDC__)
- // Turn off warning: Parameter '' is never used; effects next function only
- #pragma argsused
- #endif
-
- // Every DLL has an entry point LibMain and an exit point WEP.
- int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
- WORD wHeapSize, LPSTR lpszCmdLine )
- {
- // Required when using Zortech; causes blink to include startup code
- extern __acrtused_dll;
-
- // The startup code for the DLL initializes the local heap (if there is one)
- // with a call to LocalInit which locks the data segment.
- if ( wHeapSize != 0 )
- UnlockData( 0 );
-
- hDllInstance = hInstance;
- return 1; // Indicate that the DLL was initialized successfully.
- }
-
- int FAR PASCAL WEP(int nParam)
- {
- switch (nParam) {
- case WEP_SYSTEM_EXIT: // System shutdown in progress
- case WEP_FREE_DLL : // DLL use count is 0
- default : // Undefined; ignore
- return 1;
- }
- }
- #endif